<template>
  <div class="attendance-search">
    <!-- 页面头部 -->
    <div class="header">
      <h2><i class="el-icon-document-checked"></i> 出勤情况查询</h2>
      <div class="header-actions">
        <el-button type="primary" icon="el-icon-search" @click="handleSearch">
          查询
        </el-button>
        <el-button icon="el-icon-refresh" @click="resetSearch">
          重置
        </el-button>
        
      </div>
    </div>

    <!-- 统计概览卡片 -->
    <div class="overview-cards" v-loading="summaryLoading">
      <div class="overview-card total">
        <div class="card-icon">
          <i class="el-icon-document"></i>
        </div>
        <div class="card-content">
          <div class="card-number">{{ summaryData.totalCount || 0 }}</div>
          <div class="card-label">总记录数</div>
        </div>
      </div>
      
      <div class="overview-card present">
        <div class="card-icon">
          <i class="el-icon-check"></i>
        </div>
        <div class="card-content">
          <div class="card-number">{{ summaryData.presentCount || 0 }}</div>
          <div class="card-label">出勤次数</div>
        </div>
      </div>
      
      <div class="overview-card absent">
        <div class="card-icon">
          <i class="el-icon-close"></i>
        </div>
        <div class="card-content">
          <div class="card-number">{{ summaryData.absentCount || 0 }}</div>
          <div class="card-label">缺勤次数</div>
        </div>
      </div>
      
      <div class="overview-card rate">
        <div class="card-icon">
          <i class="el-icon-pie-chart"></i>
        </div>
        <div class="card-content">
          <div class="card-number">{{ summaryData.attendanceRate || 0 }}%</div>
          <div class="card-label">出勤率</div>
        </div>
      </div>
    </div>

    <!-- 搜索条件面板 -->
    <div class="search-panel">
      <el-form :model="searchForm" :inline="true" size="small" class="search-form">
        <el-form-item label="班级">
          <el-select v-model="searchForm.classId" placeholder="请选择班级" clearable @change="handleFormChange">
            <el-option label="全部班级" value=""></el-option>
            <el-option
              v-for="classId in classIds"
              :key="classId"
              :label="classId"
              :value="classId">
            </el-option>
          </el-select>
        </el-form-item>
        
        <el-form-item label="课程">
          <el-select v-model="searchForm.courseName" placeholder="请选择课程" clearable @change="handleFormChange">
            <el-option label="全部课程" value=""></el-option>
            <el-option
              v-for="course in courseNames"
              :key="course"
              :label="course"
              :value="course">
            </el-option>
          </el-select>
        </el-form-item>
        
        <el-form-item label="学生姓名">
          <el-select v-model="searchForm.studentName" placeholder="请选择学生" clearable filterable @change="handleFormChange">
            <el-option label="全部学生" value=""></el-option>
            <el-option
              v-for="student in studentNames"
              :key="student"
              :label="student"
              :value="student">
            </el-option>
          </el-select>
        </el-form-item>
        
        <el-form-item label="学生ID">
          <el-input 
            v-model="searchForm.studentId" 
            placeholder="请输入学生ID" 
            clearable 
            style="width: 150px;"
            @input="handleStudentIdInput"
            @keyup.enter="handleSearch"
            @clear="handleStudentIdClear">
            <template slot="suffix">
              <i class="el-icon-search" @click="handleSearch" style="cursor: pointer; color: #409EFF;"></i>
            </template>
          </el-input>
        </el-form-item>
        
        <el-form-item label="出勤状态">
          <el-select v-model="searchForm.isAbsent" placeholder="请选择状态" clearable @change="handleFormChange">
            <el-option label="全部" :value="null"></el-option>
            <el-option label="出勤" :value="false"></el-option>
            <el-option label="缺勤" :value="true"></el-option>
          </el-select>
        </el-form-item>
        
        <el-form-item label="日期范围">
          <el-date-picker
            v-model="dateRange"
            type="daterange"
            align="right"
            unlink-panels
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd"
            @change="handleDateRangeChange">
          </el-date-picker>
        </el-form-item>
      </el-form>
      
      <div class="search-status" v-if="searchForm.studentId">
        <el-tag type="info" size="small">
          <i class="el-icon-search"></i> 正在搜索学生ID: {{ searchForm.studentId }}
        </el-tag>
      </div>
    </div>

    <!-- 统计分析tabs -->
    <div class="stats-section" v-if="showStats">
      <el-tabs v-model="activeStatsTab" @tab-click="handleStatsTabClick">
        <el-tab-pane label="学生统计" name="students">
          <div class="stats-grid" v-loading="statsLoading">
            <div
              v-for="(stat, index) in studentStats"
              :key="index"
              class="stat-card">
              <div class="stat-header">
                <h4>{{ stat.name }}</h4>
                <el-tag size="small">{{ stat.id }}</el-tag>
              </div>
              <div class="stat-content">
                <div class="stat-items">
                  <div class="stat-item">
                    <span class="stat-label">总记录</span>
                    <span class="stat-value">{{ stat.totalCount }}</span>
                  </div>
                  <div class="stat-item">
                    <span class="stat-label">出勤</span>
                    <span class="stat-value present">{{ stat.presentCount }}</span>
                  </div>
                  <div class="stat-item">
                    <span class="stat-label">缺勤</span>
                    <span class="stat-value absent">{{ stat.absentCount }}</span>
                  </div>
                </div>
                <div class="stat-progress">
                  <el-progress
                    :percentage="Math.round(stat.attendanceRate)"
                    :color="getAttendanceColor(stat.attendanceRate)"
                    :show-text="false">
                  </el-progress>
                  <span class="progress-text">{{ stat.attendanceRate.toFixed(1) }}%</span>
                </div>
              </div>
            </div>
          </div>
        </el-tab-pane>
        
        <el-tab-pane label="课程统计" name="courses">
          <div class="stats-grid" v-loading="statsLoading">
            <div
              v-for="(stat, index) in courseStats"
              :key="index"
              class="stat-card">
              <div class="stat-header">
                <h4>{{ stat.name }}</h4>
                <el-tag size="small" type="success">课程</el-tag>
              </div>
              <div class="stat-content">
                <div class="stat-items">
                  <div class="stat-item">
                    <span class="stat-label">总记录</span>
                    <span class="stat-value">{{ stat.totalCount }}</span>
                  </div>
                  <div class="stat-item">
                    <span class="stat-label">出勤</span>
                    <span class="stat-value present">{{ stat.presentCount }}</span>
                  </div>
                  <div class="stat-item">
                    <span class="stat-label">缺勤</span>
                    <span class="stat-value absent">{{ stat.absentCount }}</span>
                  </div>
                </div>
                <div class="stat-progress">
                  <el-progress
                    :percentage="Math.round(stat.attendanceRate)"
                    :color="getAttendanceColor(stat.attendanceRate)"
                    :show-text="false">
                  </el-progress>
                  <span class="progress-text">{{ stat.attendanceRate.toFixed(1) }}%</span>
                </div>
              </div>
            </div>
          </div>
        </el-tab-pane>
        
        <el-tab-pane label="班级统计" name="classes">
          <div class="stats-grid" v-loading="statsLoading">
            <div
              v-for="(stat, index) in classStats"
              :key="index"
              class="stat-card">
              <div class="stat-header">
                <h4>{{ stat.name }}</h4>
                <el-tag size="small" type="warning">班级</el-tag>
              </div>
              <div class="stat-content">
                <div class="stat-items">
                  <div class="stat-item">
                    <span class="stat-label">总记录</span>
                    <span class="stat-value">{{ stat.totalCount }}</span>
                  </div>
                  <div class="stat-item">
                    <span class="stat-label">出勤</span>
                    <span class="stat-value present">{{ stat.presentCount }}</span>
                  </div>
                  <div class="stat-item">
                    <span class="stat-label">缺勤</span>
                    <span class="stat-value absent">{{ stat.absentCount }}</span>
                  </div>
                </div>
                <div class="stat-progress">
                  <el-progress
                    :percentage="Math.round(stat.attendanceRate)"
                    :color="getAttendanceColor(stat.attendanceRate)"
                    :show-text="false">
                  </el-progress>
                  <span class="progress-text">{{ stat.attendanceRate.toFixed(1) }}%</span>
                </div>
              </div>
            </div>
          </div>
        </el-tab-pane>
      </el-tabs>
    </div>

    <!-- 搜索结果表格 -->
    <div class="table-panel">
      <div class="table-header">
        <div class="table-info">
          <span>共找到 <strong>{{ total }}</strong> 条记录</span>
          
        </div>
        <div class="table-controls">
          <el-select v-model="pageSize" @change="handlePageSizeChange" size="small">
            <el-option :value="10" label="10条/页"></el-option>
            <el-option :value="20" label="20条/页"></el-option>
            <el-option :value="50" label="50条/页"></el-option>
            <el-option :value="100" label="100条/页"></el-option>
          </el-select>
        </div>
      </div>
      
      <el-table
        :data="attendanceRecords"
        v-loading="loading"
        stripe
        border
        height="500"
        @sort-change="handleSortChange">
        
        <el-table-column prop="id" label="ID" width="80" sortable="custom"></el-table-column>
        <el-table-column prop="classId" label="班级" width="100" sortable="custom"></el-table-column>
        <el-table-column prop="studentName" label="学生姓名" width="120" sortable="custom"></el-table-column>
        <el-table-column prop="studentId" label="学生ID" width="150">
          <template slot-scope="scope">
            <el-tag 
              :type="scope.row.studentId === searchForm.studentId ? 'warning' : 'info'" 
              size="small">
              {{ scope.row.studentId }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="courseName" label="课程" width="100" sortable="custom"></el-table-column>
        <el-table-column prop="score" label="分数" width="80" sortable="custom" align="center">
          <template slot-scope="scope">
            <el-tag :type="scope.row.score === 100 ? 'success' : 'danger'" size="small">
              {{ scope.row.score }}
            </el-tag>
          </template>
        </el-table-column>
        <!-- 修复出勤状态显示 -->
        <el-table-column label="出勤状态" width="100" align="center">
          <template slot-scope="scope">
            <el-tag
              :type="getAttendanceTagType(scope.row.isAbsent)"
              size="small">
              {{ getAttendanceText(scope.row.isAbsent) }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="timestamp" label="记录时间" width="160" sortable="custom">
          <template slot-scope="scope">
            {{ formatTime(scope.row.timestamp) }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="120" fixed="right" align="center">
          <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              icon="el-icon-view"
              @click="viewDetails(scope.row)">
              详情
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      
      <!-- 分页组件 -->
      <el-pagination
        @size-change="handlePageSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        style="margin-top: 20px; text-align: right;">
      </el-pagination>
    </div>

    <!-- 详情对话框 -->
    <el-dialog title="出勤记录详情" :visible.sync="detailDialogVisible" width="600px">
      <div v-if="selectedRecord" class="detail-content">
        <el-descriptions :column="2" border>
          <el-descriptions-item label="记录ID">{{ selectedRecord.id }}</el-descriptions-item>
          <el-descriptions-item label="班级">{{ selectedRecord.classId }}</el-descriptions-item>
          <el-descriptions-item label="学生姓名">{{ selectedRecord.studentName }}</el-descriptions-item>
          <el-descriptions-item label="学生ID">{{ selectedRecord.studentId }}</el-descriptions-item>
          <el-descriptions-item label="课程">{{ selectedRecord.courseName }}</el-descriptions-item>
          <el-descriptions-item label="分数">
            <el-tag :type="selectedRecord.score === 100 ? 'success' : 'danger'">
              {{ selectedRecord.score }}
            </el-tag>
          </el-descriptions-item>
          <el-descriptions-item label="出勤状态">
            <el-tag :type="getAttendanceTagType(selectedRecord.isAbsent)">
              {{ getAttendanceText(selectedRecord.isAbsent) }}
            </el-tag>
          </el-descriptions-item>
          <el-descriptions-item label="记录时间">{{ formatTime(selectedRecord.timestamp) }}</el-descriptions-item>
        </el-descriptions>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="detailDialogVisible = false">关闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: 'AttendanceSearch',
  data() {
    return {
      // 搜索表单
      searchForm: {
        classId: '',
        studentName: '',
        courseName: '',
        studentId: '',
        isAbsent: null,
        startDate: '',
        endDate: ''
      },
      
      // 日期范围
      dateRange: [],
      
      // 选项数据
      classIds: [],
      courseNames: [],
      studentNames: [],
      
      // 表格数据
      attendanceRecords: [],
      total: 0,
      currentPage: 1,
      pageSize: 20,
      loading: false,
      
      // 排序
      sortBy: 'timestamp',
      sortOrder: 'desc',
      
      // 统计数据
      showStats: false,
      activeStatsTab: 'students',
      studentStats: [],
      courseStats: [],
      classStats: [],
      statsLoading: false,
      
      // 摘要数据
      summaryData: {},
      summaryLoading: false,
      
      // 详情对话框
      detailDialogVisible: false,
      selectedRecord: null,
      
      // 搜索定时器
      searchTimer: null,
      studentIdTimer: null
    }
  },
  
  mounted() {
    this.init()
  },
  
  methods: {
    async init() {
      await this.fetchOptions()
      await this.fetchSummary()
      await this.searchAttendance()
    },
    
    async fetchOptions() {
      try {
        // 获取班级列表
        const classResponse = await this.$request.post('/classes', {})
        if (classResponse.success) {
          this.classIds = classResponse.data
        }
        
        // 获取课程列表
        const courseResponse = await this.$request.post('/courses', {})
        if (courseResponse.success) {
          this.courseNames = courseResponse.data
        }
        
        // 获取学生列表
        const studentResponse = await this.$request.post('/students', {})
        if (studentResponse.success) {
          this.studentNames = studentResponse.data
        }
      } catch (error) {
        console.error('获取选项数据失败:', error)
        this.$message.error('获取选项数据失败')
      }
    },
    
    async fetchSummary() {
      this.summaryLoading = true
      try {
        const response = await this.$request.post('/stats/summary', {
          ...this.searchForm,
          user: 'hoaixanghao',
          timestamp: new Date().toISOString()
        })
        
        if (response.success) {
          this.summaryData = response.data
        }
      } catch (error) {
        console.error('获取统计摘要失败:', error)
      } finally {
        this.summaryLoading = false
      }
    },
    
    // 核心修复：确保数据正确覆盖
    async searchAttendance() {
      this.loading = true
      
      // 先清空数据，确保覆盖
      this.attendanceRecords = []
      this.total = 0
      
      try {
        console.log('开始搜索，条件:', this.searchForm)
        console.log('分页信息:', { page: this.currentPage, pageSize: this.pageSize })
        
        const response = await this.$request.post('/search', {
          ...this.searchForm,
          page: this.currentPage,
          pageSize: this.pageSize,
          sortBy: this.sortBy,
          sortOrder: this.sortOrder,
          user: 'hoaixanghao',
          timestamp: new Date().toISOString()
        })
        
        console.log('搜索响应:', response)
        
        if (response.success) {
          // 确保数据完全覆盖
          this.attendanceRecords = response.data.records || []
          this.total = response.data.total || 0
          
          console.log('设置新数据:', {
            records: this.attendanceRecords.length,
            total: this.total
          })
          
          // 同时更新摘要数据
          await this.fetchSummary()
        } else {
          this.$message.error(response.message || '搜索失败')
          // 搜索失败时也要清空数据
          this.attendanceRecords = []
          this.total = 0
        }
      } catch (error) {
        console.error('搜索出勤记录失败:', error)
        this.$message.error('搜索出勤记录失败')
        // 出错时清空数据
        this.attendanceRecords = []
        this.total = 0
      } finally {
        this.loading = false
      }
      
      // 如果显示统计，则获取统计数据
      if (this.showStats) {
        await this.fetchStats()
      }
    },
    
    // 处理学生ID输入
    handleStudentIdInput(value) {
      console.log('学生ID输入变化:', value)
      
      // 清除之前的定时器
      if (this.studentIdTimer) {
        clearTimeout(this.studentIdTimer)
      }
      
      // 重置到第一页
      this.currentPage = 1
      
      // 防抖搜索 - 800ms延迟
      this.studentIdTimer = setTimeout(() => {
        console.log('执行学生ID搜索')
        this.searchAttendance()
      }, 800)
    },
    
    // 处理学生ID清空
    handleStudentIdClear() {
      console.log('学生ID已清空')
      this.currentPage = 1
      this.searchAttendance()
    },
    
    // 处理表单变化时的搜索
    handleFormChange() {
      console.log('表单其他字段变化')
      // 重置到第一页
      this.currentPage = 1
      // 延迟搜索，避免频繁请求
      this.debounceSearch()
    },
    
    // 防抖搜索
    debounceSearch() {
      if (this.searchTimer) {
        clearTimeout(this.searchTimer)
      }
      this.searchTimer = setTimeout(() => {
        this.searchAttendance()
      }, 500)
    },
    
    // 手动搜索按钮
    handleSearch() {
      console.log('手动点击搜索按钮')
      this.currentPage = 1
      this.searchAttendance()
    },
    
    async fetchStats() {
      this.statsLoading = true
      try {
        const searchCondition = {
          classId: this.searchForm.classId,
          courseName: this.searchForm.courseName,
          studentName: this.searchForm.studentName,
          studentId: this.searchForm.studentId,
          startDate: this.searchForm.startDate,
          endDate: this.searchForm.endDate,
          user: 'hoaixanghao',
          timestamp: new Date().toISOString()
        }
        
        // 根据当前tab获取对应统计
        if (this.activeStatsTab === 'students') {
          const response = await this.$request.post('/stats/students', searchCondition)
          if (response.success) {
            this.studentStats = response.data
          }
        } else if (this.activeStatsTab === 'courses') {
          const response = await this.$request.post('/stats/courses', searchCondition)
          if (response.success) {
            this.courseStats = response.data
          }
        } else if (this.activeStatsTab === 'classes') {
          const response = await this.$request.post('/stats/classes', searchCondition)
          if (response.success) {
            this.classStats = response.data
          }
        }
      } catch (error) {
        console.error('获取统计数据失败:', error)
        this.$message.error('获取统计数据失败')
      } finally {
        this.statsLoading = false
      }
    },
    
    handleDateRangeChange(value) {
      if (value && value.length === 2) {
        this.searchForm.startDate = value[0]
        this.searchForm.endDate = value[1]
      } else {
        this.searchForm.startDate = ''
        this.searchForm.endDate = ''
      }
      this.handleFormChange()
    },
    
    resetSearch() {
      console.log('重置搜索条件')
      // 重置表单
      this.searchForm = {
        classId: '',
        studentName: '',
        courseName: '',
        studentId: '',
        isAbsent: null,
        startDate: '',
        endDate: ''
      }
      this.dateRange = []
      
      // 重置分页
      this.currentPage = 1
      
      // 重新搜索
      this.searchAttendance()
    },
    
    async toggleStats() {
      this.showStats = !this.showStats
      if (this.showStats) {
        await this.fetchStats()
      }
    },
    
    async handleStatsTabClick(tab) {
      this.activeStatsTab = tab.name
      await this.fetchStats()
    },
    
    handlePageSizeChange(val) {
      this.pageSize = val
      this.currentPage = 1 // 重置到第一页
      this.searchAttendance()
    },
    
    handleCurrentChange(val) {
      this.currentPage = val
      this.searchAttendance()
    },
    
    handleSortChange(sortInfo) {
      this.sortBy = sortInfo.prop || 'timestamp'
      this.sortOrder = sortInfo.order === 'ascending' ? 'asc' : 'desc'
      this.currentPage = 1 // 重置到第一页
      this.searchAttendance()
    },
    
    viewDetails(record) {
      this.selectedRecord = record
      this.detailDialogVisible = true
    },
    
    exportData() {
      // 导出功能实现
      this.$message.info('导出功能开发中...')
    },
    
    getAttendanceColor(rate) {
      if (rate >= 90) return '#67c23a'
      if (rate >= 80) return '#e6a23c'
      if (rate >= 70) return '#f56c6c'
      return '#909399'
    },
    
    // 新增：获取出勤状态文本（支持布尔值）
    getAttendanceText(isAbsent) {
      // 处理布尔值和数字值两种情况
      if (isAbsent === true || isAbsent === 1) {
        return '缺勤'
      } else if (isAbsent === false || isAbsent === 0) {
        return '出勤'
      }
      return '未知'
    },
    
    // 新增：获取出勤状态标签类型（支持布尔值）
    getAttendanceTagType(isAbsent) {
      // 处理布尔值和数字值两种情况
      if (isAbsent === true || isAbsent === 1) {
        return 'danger'  // 缺勤显示红色
      } else if (isAbsent === false || isAbsent === 0) {
        return 'success' // 出勤显示绿色
      }
      return 'info'      // 未知显示灰色
    },
    
    formatTime(timeStr) {
      if (!timeStr) return '未知'
      try {
        return new Date(timeStr).toLocaleString('zh-CN', {
          year: 'numeric',
          month: '2-digit',
          day: '2-digit',
          hour: '2-digit',
          minute: '2-digit',
          second: '2-digit'
        })
      } catch (error) {
        return '时间格式错误'
      }
    }
  },
  
  // 组件销毁时清理定时器
  beforeDestroy() {
    if (this.searchTimer) {
      clearTimeout(this.searchTimer)
    }
    if (this.studentIdTimer) {
      clearTimeout(this.studentIdTimer)
    }
  }
}
</script>

<style scoped>
/* 样式保持不变 */
.attendance-search {
  padding: 20px;
  background: #f5f7fa;
  min-height: 100vh;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding: 20px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.header h2 {
  margin: 0;
  color: #303133;
}

.header-actions {
  display: flex;
  gap: 10px;
}

/* 概览卡片样式 */
.overview-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  margin-bottom: 20px;
}

.overview-card {
  background: white;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  gap: 15px;
  transition: all 0.3s ease;
}

.overview-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.overview-card.total .card-icon {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.overview-card.present .card-icon {
  background: linear-gradient(135deg, #4CAF50 0%, #45a049 100%);
}

.overview-card.absent .card-icon {
  background: linear-gradient(135deg, #f44336 0%, #d32f2f 100%);
}

.overview-card.rate .card-icon {
  background: linear-gradient(135deg, #ff9800 0%, #f57c00 100%);
}

.card-icon {
  width: 50px;
  height: 50px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 24px;
}

.card-content {
  flex: 1;
}

.card-number {
  font-size: 24px;
  font-weight: bold;
  color: #303133;
  margin-bottom: 5px;
}

.card-label {
  color: #909399;
  font-size: 14px;
}

.search-panel {
  background: white;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  margin-bottom: 20px;
}

.search-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.search-status {
  margin-top: 15px;
  padding-top: 15px;
  border-top: 1px solid #ebeef5;
}

.stats-section {
  background: white;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  margin-bottom: 20px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
  margin-top: 20px;
}

.stat-card {
  background: #f8f9fa;
  border: 1px solid #e9ecef;
  border-radius: 8px;
  padding: 20px;
  transition: all 0.3s ease;
}

.stat-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transform: translateY(-2px);
}

.stat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
}

.stat-header h4 {
  margin: 0;
  color: #303133;
  font-size: 16px;
}

.stat-content {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.stat-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stat-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.stat-label {
  color: #606266;
  font-size: 14px;
}

.stat-value {
  font-weight: bold;
  font-size: 16px;
}

.stat-value.present {
  color: #67c23a;
}

.stat-value.absent {
  color: #f56c6c;
}

.stat-progress {
  display: flex;
  align-items: center;
  gap: 10px;
}

.progress-text {
  font-weight: bold;
  color: #303133;
  min-width: 45px;
}

.table-panel {
  background: white;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.table-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.table-info {
  display: flex;
  align-items: center;
  gap: 15px;
}

.table-info .el-button.active {
  color: #409eff;
}

.table-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.detail-content {
  padding: 20px 0;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .header {
    flex-direction: column;
    gap: 15px;
  }
  
  .header-actions {
    width: 100%;
    justify-content: center;
  }
  
  .overview-cards {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .search-form {
    flex-direction: column;
  }
  
  .search-form .el-form-item {
    margin-bottom: 10px;
  }
  
  .stats-grid {
    grid-template-columns: 1fr;
  }
  
  .table-header {
    flex-direction: column;
    gap: 15px;
  }
}

@media (max-width: 480px) {
  .overview-cards {
    grid-template-columns: 1fr;
  }
}
</style>